clear all

cd "~\Data"
use "study4_raw.dta"


*attention check
rename populism_full_7 check_grid
recode check_grid 5=1 *=0
tab check_grid

*demos
gen white=0
replace white=1 if ethnicity=="1"
recode hispanic 2=0
recode gender 2/3=0, gen(male)
rename political_ideology ideo
rename political_party_preference PID
recode PID 98/99=4

*recoding conspiracy
recode conspiracy_1 conspiracy_2 conspiracy_3 conspiracy_4 (1=5) (2=4) (4=2) (5=1)

*recoding chaos
recode chaos1_1 chaos1_2 chaos1_3 chaos2_1 chaos2_2 chaos2_3 chaos2_4 (1=5) (2=4) (4=2) (5=1)

*recoding violence
recode violence_1 violence_2 violence_3 violence_4 (1=5) (2=4) (4=2) (5=1)

*recoding populism
recode populism_full_1 populism_full_2 populism_full_3 (1=5) (2=4) (4=2) (5=1)

*recoding HS
recode hs_full_1 hs_full_2 hs_full_3 (1=5) (2=4) (4=2) (5=1)

*recoding RR
recode raceresent_1 raceresent_2 (1=5) (2=4) (4=2) (5=1)

*recoding anti-democratic
recode antidem_1 antidem_2 antidem_3 antidem_4 (1=5) (2=4) (4=2) (5=1)


*scales
alpha conspiracy*, item casewise gen(Consp_full)
alpha chaos*, item casewise gen(Chaos_full)
alpha violence*, item casewise gen(Violence_full)
alpha populism_full*, item casewise gen(Pop_full)
alpha hs_full*, item casewise gen(HS_full)
alpha raceresent*, item casewise gen(RR_full)
alpha antidem*, item casewise gen(Anti_full)


*creating scale halves
alpha conspiracy_1 conspiracy_2 conspiracy_3 conspiracy_4, item casewise gen(consp_for)
alpha conspiracy_5 conspiracy_6 conspiracy_7 conspiracy_8 conspiracy_9, item casewise gen(consp_rev_with7) 
alpha conspiracy_5 conspiracy_6 conspiracy_8 conspiracy_9, item casewise gen(consp_rev) /* dropped item 7*/
cor consp_for consp_rev consp_rev_with7

alpha chaos1_1 chaos1_2 chaos1_3 chaos2_1 chaos2_2 chaos2_3 chaos2_4, item casewise gen(chaos_for)
alpha chaos1_4 chaos1_5 chaos1_6 chaos1_7 chaos2_5 chaos2_6 chaos2_7 chaos2_8, item casewise gen(chaos_rev_with6) /* maybe drop item 2_6 */
alpha chaos1_4 chaos1_5 chaos1_6 chaos1_7 chaos2_5  chaos2_7 chaos2_8, item casewise gen(chaos_rev) /* dropped item 2_6 */
cor chaos_for chaos_rev chaos_rev_with6

alpha violence_1 violence_2 violence_3 violence_4, item casewise gen(violence_for)
alpha violence_5 violence_6 violence_7 violence_8, item casewise gen(violence_rev)
cor violence_for violence_rev

alpha populism_full_1 populism_full_2 populism_full_3, item casewise gen(pop_for)
alpha populism_full_4 populism_full_5 populism_full_6, item casewise gen(pop_rev)
cor pop_for pop_rev

alpha hs_full_1 hs_full_2 hs_full_3, item casewise gen(hs_for)
alpha hs_full_4 hs_full_5 hs_full_6, item casewise gen(hs_rev)
cor hs_for hs_rev
alpha hs_full_*, item casewise gen(hs_full)

alpha antidem_1 antidem_2 antidem_3 antidem_4, item casewise gen(anti_for)
alpha antidem_5 antidem_6 antidem_7 antidem_8, item casewise gen(anti_rev)
cor anti_for anti_rev

alpha raceresent_1 raceresent_2, item casewise gen(rr_for)
alpha raceresent_3 raceresent_4, item casewise gen(rr_rev)
alpha raceresent_*, item casewise gen(rr_full)
cor rr_for rr_rev

rename Pop_full popu_full
rename pop_for popu_for

rename Anti_full anti_full

rename Consp_full consp_full

rename Chaos_full chaos_full

rename Violence_full viol_full
rename violence_for viol_for


***
*
*********************

cd "C:\Users\scottclifford\Dropbox\Research\Acquiescence Bias\Study 4\Sims"


*RR
foreach x in hs viol consp chaos anti popu {
	gen `x'_b_rr=.
	gen `x'_se_rr=.
	gen `x'_dv_rr="`x'"
	gen `x'_iv_rr="rr"

	reg `x'_full rr_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_rr=_b[rr_full] in 1
	replace `x'_se_rr=_se[rr_full] in 1

	reg `x'_full rr_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_rr=_b[rr_for] in 2
	replace `x'_se_rr=_se[rr_for] in 2

	reg `x'_for rr_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_rr=_b[rr_full] in 3
	replace `x'_se_rr=_se[rr_full] in 3

	reg `x'_for rr_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_rr=_b[rr_for] in 4
	replace `x'_se_rr=_se[rr_for] in 4

	gen `x'_lo_rr=`x'_b_rr-1.96*`x'_se_rr
	gen `x'_hi_rr=`x'_b_rr+1.96*`x'_se_rr
	
}

rename hs_b_rr beta1
rename hs_lo_rr lo1
rename hs_hi_rr hi1
rename hs_dv_rr dv1
rename hs_iv_rr iv1

rename viol_b_rr beta2
rename viol_lo_rr lo2
rename viol_hi_rr hi2
rename viol_dv_rr dv2
rename viol_iv_rr iv2

rename consp_b_rr beta3
rename consp_lo_rr lo3
rename consp_hi_rr hi3
rename consp_dv_rr dv3
rename consp_iv_rr iv3

rename chaos_b_rr beta4
rename chaos_lo_rr lo4
rename chaos_hi_rr hi4
rename chaos_dv_rr dv4
rename chaos_iv_rr iv4

rename anti_b_rr beta5
rename anti_lo_rr lo5
rename anti_hi_rr hi5
rename anti_dv_rr dv5
rename anti_iv_rr iv5

rename popu_b_rr beta6
rename popu_lo_rr lo6
rename popu_hi_rr hi6
rename popu_dv_rr dv6
rename popu_iv_rr iv6


*HS
foreach x in rr viol consp chaos anti popu {
	gen `x'_b_hs=.
	gen `x'_se_hs=.
	gen `x'_dv_hs="`x'"
	gen `x'_iv_hs="hs"

	reg `x'_full hs_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_hs=_b[hs_full] in 1
	replace `x'_se_hs=_se[hs_full] in 1

	reg `x'_full hs_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_hs=_b[hs_for] in 2
	replace `x'_se_hs=_se[hs_for] in 2

	reg `x'_for hs_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_hs=_b[hs_full] in 3
	replace `x'_se_hs=_se[hs_full] in 3

	reg `x'_for hs_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_hs=_b[hs_for] in 4
	replace `x'_se_hs=_se[hs_for] in 4

	gen `x'_lo_hs=`x'_b_hs-1.96*`x'_se_hs
	gen `x'_hi_hs=`x'_b_hs+1.96*`x'_se_hs
	
}

rename rr_b_hs beta7
rename rr_lo_hs lo7
rename rr_hi_hs hi7
rename rr_dv_hs dv7
rename rr_iv_hs iv7

rename viol_b_hs beta8
rename viol_lo_hs lo8
rename viol_hi_hs hi8
rename viol_dv_hs dv8
rename viol_iv_hs iv8

rename consp_b_hs beta9
rename consp_lo_hs lo9
rename consp_hi_hs hi9
rename consp_dv_hs dv9
rename consp_iv_hs iv9

rename chaos_b_hs beta10
rename chaos_lo_hs lo10
rename chaos_hi_hs hi10
rename chaos_dv_hs dv10
rename chaos_iv_hs iv10

rename anti_b_hs beta11
rename anti_lo_hs lo11
rename anti_hi_hs hi11
rename anti_dv_hs dv11
rename anti_iv_hs iv11

rename popu_b_hs beta12
rename popu_lo_hs lo12
rename popu_hi_hs hi12
rename popu_dv_hs dv12
rename popu_iv_hs iv12


*Viol
foreach x in rr hs consp chaos anti popu {
	gen `x'_b_viol=.
	gen `x'_se_viol=.
	gen `x'_dv_viol="`x'"
	gen `x'_iv_viol="viol"

	reg `x'_full viol_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_viol=_b[viol_full] in 1
	replace `x'_se_viol=_se[viol_full] in 1

	reg `x'_full viol_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_viol=_b[viol_for] in 2
	replace `x'_se_viol=_se[viol_for] in 2

	reg `x'_for viol_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_viol=_b[viol_full] in 3
	replace `x'_se_viol=_se[viol_full] in 3

	reg `x'_for viol_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_viol=_b[viol_for] in 4
	replace `x'_se_viol=_se[viol_for] in 4

	gen `x'_lo_viol=`x'_b_viol-1.96*`x'_se_viol
	gen `x'_hi_viol=`x'_b_viol+1.96*`x'_se_viol
	
}

rename rr_b_viol beta13
rename rr_lo_viol lo13
rename rr_hi_viol hi13
rename rr_dv_viol dv13
rename rr_iv_viol iv13

rename hs_b_viol beta14
rename hs_lo_viol lo14
rename hs_hi_viol hi14
rename hs_dv_viol dv14
rename hs_iv_viol iv14

rename consp_b_viol beta15
rename consp_lo_viol lo15
rename consp_hi_viol hi15
rename consp_dv_viol dv15
rename consp_iv_viol iv15

rename chaos_b_viol beta16
rename chaos_lo_viol lo16
rename chaos_hi_viol hi16
rename chaos_dv_viol dv16
rename chaos_iv_viol iv16

rename anti_b_viol beta17
rename anti_lo_viol lo17
rename anti_hi_viol hi17
rename anti_dv_viol dv17
rename anti_iv_viol iv17

rename popu_b_viol beta18
rename popu_lo_viol lo18
rename popu_hi_viol hi18
rename popu_dv_viol dv18
rename popu_iv_viol iv18


*Consp
foreach x in rr hs viol chaos anti popu {
	gen `x'_b_consp=.
	gen `x'_se_consp=.
	gen `x'_dv_consp="`x'"
	gen `x'_iv_consp="consp"

	reg `x'_full consp_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_consp=_b[consp_full] in 1
	replace `x'_se_consp=_se[consp_full] in 1

	reg `x'_full consp_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_consp=_b[consp_for] in 2
	replace `x'_se_consp=_se[consp_for] in 2

	reg `x'_for consp_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_consp=_b[consp_full] in 3
	replace `x'_se_consp=_se[consp_full] in 3

	reg `x'_for consp_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_consp=_b[consp_for] in 4
	replace `x'_se_consp=_se[consp_for] in 4

	gen `x'_lo_consp=`x'_b_consp-1.96*`x'_se_consp
	gen `x'_hi_consp=`x'_b_consp+1.96*`x'_se_consp
	
}

rename rr_b_consp beta19
rename rr_lo_consp lo19
rename rr_hi_consp hi19
rename rr_dv_consp dv19
rename rr_iv_consp iv19

rename hs_b_consp beta20
rename hs_lo_consp lo20
rename hs_hi_consp hi20
rename hs_dv_consp dv20
rename hs_iv_consp iv20

rename viol_b_consp beta21
rename viol_lo_consp lo21
rename viol_hi_consp hi21
rename viol_dv_consp dv21
rename viol_iv_consp iv21

rename chaos_b_consp beta22
rename chaos_lo_consp lo22
rename chaos_hi_consp hi22
rename chaos_dv_consp dv22
rename chaos_iv_consp iv22

rename anti_b_consp beta23
rename anti_lo_consp lo23
rename anti_hi_consp hi23
rename anti_dv_consp dv23
rename anti_iv_consp iv23

rename popu_b_consp beta24
rename popu_lo_consp lo24
rename popu_hi_consp hi24
rename popu_dv_consp dv24
rename popu_iv_consp iv24


*Chaos
foreach x in rr hs viol consp anti popu {
	gen `x'_b_chaos=.
	gen `x'_se_chaos=.
	gen `x'_dv_chaos="`x'"
	gen `x'_iv_chaos="chaos"

	reg `x'_full chaos_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_chaos=_b[chaos_full] in 1
	replace `x'_se_chaos=_se[chaos_full] in 1

	reg `x'_full chaos_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_chaos=_b[chaos_for] in 2
	replace `x'_se_chaos=_se[chaos_for] in 2

	reg `x'_for chaos_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_chaos=_b[chaos_full] in 3
	replace `x'_se_chaos=_se[chaos_full] in 3

	reg `x'_for chaos_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_chaos=_b[chaos_for] in 4
	replace `x'_se_chaos=_se[chaos_for] in 4

	gen `x'_lo_chaos=`x'_b_chaos-1.96*`x'_se_chaos
	gen `x'_hi_chaos=`x'_b_chaos+1.96*`x'_se_chaos
	
}

rename rr_b_chaos beta25
rename rr_lo_chaos lo25
rename rr_hi_chaos hi25
rename rr_dv_chaos dv25
rename rr_iv_chaos iv25

rename hs_b_chaos beta26
rename hs_lo_chaos lo26
rename hs_hi_chaos hi26
rename hs_dv_chaos dv26
rename hs_iv_chaos iv26

rename viol_b_chaos beta27
rename viol_lo_chaos lo27
rename viol_hi_chaos hi27
rename viol_dv_chaos dv27
rename viol_iv_chaos iv27

rename consp_b_chaos beta28
rename consp_lo_chaos lo28
rename consp_hi_chaos hi28
rename consp_dv_chaos dv28
rename consp_iv_chaos iv28

rename anti_b_chaos beta29
rename anti_lo_chaos lo29
rename anti_hi_chaos hi29
rename anti_dv_chaos dv29
rename anti_iv_chaos iv29

rename popu_b_chaos beta30
rename popu_lo_chaos lo30
rename popu_hi_chaos hi30
rename popu_dv_chaos dv30
rename popu_iv_chaos iv30


*Anti
foreach x in rr hs viol consp chaos popu {
	gen `x'_b_anti=.
	gen `x'_se_anti=.
	gen `x'_dv_anti="`x'"
	gen `x'_iv_anti="anti"

	reg `x'_full anti_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_anti=_b[anti_full] in 1
	replace `x'_se_anti=_se[anti_full] in 1

	reg `x'_full anti_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_anti=_b[anti_for] in 2
	replace `x'_se_anti=_se[anti_for] in 2

	reg `x'_for anti_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_anti=_b[anti_full] in 3
	replace `x'_se_anti=_se[anti_full] in 3

	reg `x'_for anti_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_anti=_b[anti_for] in 4
	replace `x'_se_anti=_se[anti_for] in 4

	gen `x'_lo_anti=`x'_b_anti-1.96*`x'_se_anti
	gen `x'_hi_anti=`x'_b_anti+1.96*`x'_se_anti
	
}

rename rr_b_anti beta31
rename rr_lo_anti lo31
rename rr_hi_anti hi31
rename rr_dv_anti dv31
rename rr_iv_anti iv31

rename hs_b_anti beta32
rename hs_lo_anti lo32
rename hs_hi_anti hi32
rename hs_dv_anti dv32
rename hs_iv_anti iv32

rename viol_b_anti beta33
rename viol_lo_anti lo33
rename viol_hi_anti hi33
rename viol_dv_anti dv33
rename viol_iv_anti iv33

rename consp_b_anti beta34
rename consp_lo_anti lo34
rename consp_hi_anti hi34
rename consp_dv_anti dv34
rename consp_iv_anti iv34

rename chaos_b_anti beta35
rename chaos_lo_anti lo35
rename chaos_hi_anti hi35
rename chaos_dv_anti dv35
rename chaos_iv_anti iv35

rename popu_b_anti beta36
rename popu_lo_anti lo36
rename popu_hi_anti hi36
rename popu_dv_anti dv36
rename popu_iv_anti iv36


*Popu
foreach x in rr hs viol consp chaos anti {
	gen `x'_b_popu=.
	gen `x'_se_popu=.
	gen `x'_dv_popu="`x'"
	gen `x'_iv_popu="popu"

	reg `x'_full popu_full white hispanic age male PID ideo
	est store `x'1
	replace `x'_b_popu=_b[popu_full] in 1
	replace `x'_se_popu=_se[popu_full] in 1

	reg `x'_full popu_for white hispanic age male PID ideo
	est store `x'2
	replace `x'_b_popu=_b[popu_for] in 2
	replace `x'_se_popu=_se[popu_for] in 2

	reg `x'_for popu_full white hispanic age male PID ideo
	est store `x'3
	replace `x'_b_popu=_b[popu_full] in 3
	replace `x'_se_popu=_se[popu_full] in 3

	reg `x'_for popu_for white hispanic age male PID ideo
	est store `x'4
	replace `x'_b_popu=_b[popu_for] in 4
	replace `x'_se_popu=_se[popu_for] in 4

	gen `x'_lo_popu=`x'_b_popu-1.96*`x'_se_popu
	gen `x'_hi_popu=`x'_b_popu+1.96*`x'_se_popu
	
}

rename rr_b_popu beta37
rename rr_lo_popu lo37
rename rr_hi_popu hi37
rename rr_dv_popu dv37
rename rr_iv_popu iv37

rename hs_b_popu beta38
rename hs_lo_popu lo38
rename hs_hi_popu hi38
rename hs_dv_popu dv38
rename hs_iv_popu iv38

rename viol_b_popu beta39
rename viol_lo_popu lo39
rename viol_hi_popu hi39
rename viol_dv_popu dv39
rename viol_iv_popu iv39

rename consp_b_popu beta40
rename consp_lo_popu lo40
rename consp_hi_popu hi40
rename consp_dv_popu dv40
rename consp_iv_popu iv40

rename chaos_b_popu beta41
rename chaos_lo_popu lo41
rename chaos_hi_popu hi41
rename chaos_dv_popu dv41
rename chaos_iv_popu iv41

rename anti_b_popu beta42
rename anti_lo_popu lo42
rename anti_hi_popu hi42
rename anti_dv_popu dv42
rename anti_iv_popu iv42



*trimming data
keep beta* lo* hi* dv* iv*
keep if _n<5


*reshaping
gen ID=_n
reshape long beta lo hi dv iv, i(ID) j(coef)

*create indicator of sign and significance
gen signsig=lo*hi
recode signsig -100/-.00001=0
replace signsig=1 if (lo>0 & hi>0)
replace signsig=-1 if (lo<0 & hi<0)

*create variable label for each model
gen ivlab=iv
gen dvlab=dv
replace ivlab="IV: Anti-Dem" if ivlab=="anti"
replace ivlab="IV: Chaos" if ivlab=="chaos"
replace ivlab="IV: Conspiracy" if ivlab=="consp"
replace ivlab="IV: Sexism" if ivlab=="hs"
replace ivlab="IV: Populism" if ivlab=="popu"
replace ivlab="IV: Racism" if ivlab=="rr"
replace ivlab="IV: Violence" if ivlab=="viol"

replace dvlab="DV: Anti-Dem" if dvlab=="anti"
replace dvlab="DV: Chaos" if dvlab=="chaos"
replace dvlab="DV: Conspiracy" if dvlab=="consp"
replace dvlab="DV: Sexism" if dvlab=="hs"
replace dvlab="DV: Populism" if dvlab=="popu"
replace dvlab="DV: Racism" if dvlab=="rr"
replace dvlab="DV: Violence" if dvlab=="viol"

gen model=ivlab + ", " + dvlab
labmask coef, values(model)

*create numeric indicator of model 
encode model, gen(modelnumber)

*summary stats
gen se=(hi-lo)/(2*1.96)

gen range=.
gen std=.
forval x=1/42 {
	sum beta if modelnumber==`x'
	replace range=r(max)-r(min) in `x' 
	replace std=r(sd) in `x'
}
gen ratio=std/se
sum range std se ratio

egen betamean=mean(beta), by(modelnumber)
sort betamean
xtile coeforder=betamean, nq(42)
labmask coeforder, values(model)

twoway scatter coeforder beta if signsig==0 & ID!=1, msymbol(Oh) mcol(stc1%60) || scatter coeforder beta if signsig==1 & ID!=1, msymbol(Oh) mcol(stc2%60) || scatter coeforder beta if signsig==-1 & ID!=1, msymbol(Oh) ylab(1(1)42, valuelabel grid labsize(vsmall)) xlab(,nogrid) xline(0) legend(off) || scatter coeforder beta if signsig==0 & ID==1, mcol(stc1%60) || scatter coeforder beta if signsig==1 & ID==1, mcol(stc2%60) xtitle("Coefficient") ytitle("Model")

